package com.liberation.aidiancan.view.fragments;

import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.liberation.aidiancan.R;
import com.liberation.aidiancan.api.Constans;
import com.liberation.aidiancan.base.BaseFragment;
import com.liberation.aidiancan.bean.HomeListBean;
import com.liberation.aidiancan.presenter.BasePresent;
import com.liberation.aidiancan.utils.JsonUtils;
import com.liberation.aidiancan.utils.NetworkUtils;
import com.orhanobut.logger.Logger;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： AiDianCan
 * 创建人 : Liberation
 * 创建时间: 2017/1/24 16:04
 */

public class HomeFragment extends BaseFragment implements NetworkUtils.GetJson {
	@BindView(R.id.tv_city_chose)
	TextView mTvCityChose;
	@BindView(R.id.tv_scan)
	TextView mTvScan;
	@BindView(R.id.tv_search)
	TextView mTvSearch;
	@BindView(R.id.rv_home)
	RecyclerView mRvHome;
	@BindView(R.id.refresh_view)
	SwipeRefreshLayout mRefreshView;
	private int requsetCount;
	private String main_url;

	@Override
	public BasePresent createPresenter() {
		return null;
	}

	@Override
	protected int getContentView() {
		return R.layout.fragment_home;
	}

	@Override
	protected void init(View view) {
		getData("珠海",false);
	}

	@Override
	protected void loadDatas() {


	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO: inflate a fragment view
		View rootView = super.onCreateView(inflater, container, savedInstanceState);
		ButterKnife.bind(this, rootView);
		return rootView;
	}

	@OnClick({R.id.tv_city_chose, R.id.tv_scan, R.id.tv_search})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.tv_city_chose:
				break;
			case R.id.tv_scan:
				break;
			case R.id.tv_search:
				break;
		}
	}

	//加载JSON数据
	private void getData(String address, boolean isLoadMore) {
		if (isLoadMore) {
			requsetCount += 20;
			main_url = String.format(Constans.HOME_LIST, address, requsetCount);
		} else {
			requsetCount = 20;
			main_url = String.format(Constans.HOME_LIST, address, requsetCount);
		}
		NetworkUtils.doHttpAsync(main_url,this,getContext());
	}

	@Override
	public void getJsonCallBack(String result, String request_url) {
		Logger.e("这里的数据"+result);
		if(request_url.equals(main_url)){
			List<HomeListBean> data = JsonUtils.getHomeListBean(request_url);
			Logger.e("这里的数据"+data.toString());
		}

	}
}
